// app.js
import './utils/utils'
import './utils/http'
App({
  onLaunch() {
    // 读取 token
    this.getToken('token')
    // 读取 refreshToken
    this.getToken('refreshToken')
  },
  getToken(key) {
    // 异步方法不会防塞
    wx.getStorage({
      key,
      success: (res) => {
        this[key] = res.data
      }
    })
  },
  setToken(token, refreshToken) {
    // 本地存储token
    wx.setStorageSync('token', `Bearer ${token}`)
    // 更新全局token
    this.token = `Bearer ${token}`
    // 存refreshToken
    wx.setStorageSync('refreshToken', `Bearer ${refreshToken}`)
    this.refreshToken = `Bearer ${refreshToken}`
  }
})